package tree.huffmanTree;

import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 创建节点类，为了让Node对象支持排序  实现Comparable接口
 */


@Data
@NoArgsConstructor
public class Node implements Comparable<Node>{
    private int weight;
    private Node left;
    private Node right;

    public Node(int weight) {
        this.weight = weight;
    }
    @Override
    public String toString() {
        return "Node{" +
                "weight=" + weight +
                '}';
    }
    @Override
    public int compareTo(Node o) {
        return this.weight-o.getWeight();
    }
    // 前序遍历
    public void preOrder(){
        System.out.print(weight+",");
        if (null!=left){
            left.preOrder();
        }
        if (null!=right){
            right.preOrder();
        }
    }
}